import util from '@/utils/util'

export default {
  inserted: (el, binding) => {
    if (!el.__vue__) {
      alert('绑定指令[v-perm="\'' + binding.value + '\'"]的标签错误，可选标签为[<el-button>]')
      return
    }
    const tag = el.__vue__.$vnode.tag.replace(/vue-component-\d+-/g, '')
    if (tag === 'ElButton') {
      const route = el.__vue__._routerRoot._route
      const hasPerm = util.hasPerm(route.fullPath.replace(/\//g, ''), binding.value)
      if (!hasPerm) {
        el.style.display = 'none'
      }
    }
  }
}
